<!DOCTYPE html>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<input id="notFocused" value="foo">
<input id="focused" value="a">
<script>
test(() => {
    var notFocused = document.getElementById('notFocused');
    var focused = document.getElementById('focused');
    var selection = window.getSelection();
    selection.removeAllRanges();
    focused.focus();

    var originalAnchorNode = selection.anchorNode;
    var originalAnchorOffset = selection.anchorOffset;
    notFocused.setSelectionRange(3, 3);
    assert_equals(selection.anchorNode, originalAnchorNode);
    assert_equals(selection.anchorOffset, originalAnchorOffset);
}, 'setSelectionRange() should not update FrameSelection if the target element is not focused.');

test(() => {
    var notFocused = document.getElementById('notFocused');
    var focused = document.getElementById('focused');
    var selection = window.getSelection();
    selection.removeAllRanges();
    focused.focus();

    var originalAnchorNode = selection.anchorNode;
    var originalAnchorOffset = selection.anchorOffset;
    notFocused.setRangeText('barrr', 0, 3, 'select');
    assert_equals(selection.anchorNode, originalAnchorNode);
    assert_equals(selection.anchorOffset, originalAnchorOffset);
}, 'setRangeText() should not update FrameSelection if the target element is not focused.');
</script>
</body>
